package com.shopping_assistant.model;

import java.util.ArrayList;
import java.util.List;

public class PersonController {

	private Person activeUser;
	
	private List<Person> persons;
	
	private static PersonController instance;
	
	public static PersonController getInstance() {
		if(instance == null)
			instance = new PersonController();
		
		return instance;
	}
	
	private PersonController() {
		persons = new ArrayList<Person>();
	}
	
	public void setActiveUser(Person activeUser) {
		this.activeUser = activeUser;
	}
	
	public Person getActiveUser() {
		return activeUser;
	}
	
	public void addPerson(Person person) {
		//TODO: Tjek at brugernavn er ledigt og password har rette format
		if(true) {
			persons.add(person);
		}
	}
	
	public void removePerson(String username) {
		for(Person object : persons) {
			if(object.getUsername().equals(username)) {
				persons.remove(object);
			}
		}
	}
	
	public List<Person> getPersons() {
		return persons;
	}
}
